﻿@using mscook.mvc;
@{
    ViewBag.Title = "GenTemplate";
    Layout = "../Shared/_Layout.cshtml";
}

@model mscook.mvc.Areas.weblogin.Models.GenTemplateModel


<div id="hotelModal" class="modal hide fade form-horizontal">
</div>
<div id="chefModal" class="modal hide fade form-horizontal">
</div>
<div id="cookBookModal" class="modal hide fade form-horizontal">
</div>
<div id="bulletinModal" class="modal hide fade form-horizontal">
</div>

<div id="alertModal" class="modal hide fade form-horizontal" title="提示框" aria-hidden="false" style="display: none;">
    <div class="modal-header">
        <h4>提示框</h4>
    </div>

    <div class="modal-body">
        <div>
            上传成功！
        </div>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn btn-primary" data-dismiss="modal">关闭</a>
    </div>

</div>
<div>
    <ul class="breadcrumb">
        <li>
            <a href="@Url.Action("", "home")">首页</a> <span class="divider">/</span>
        </li>
        <li>
            <a href="@Url.Action("", "magazine")">杂志</a><span class="divider">/</span>
        </li>
        <li>
            <a href="@Url.Action("ArticleIndex/" + Model.ArticleKey.Year + "/" + Model.ArticleKey.Month, "magazine")">文章</a><span class="divider">/</span>
        </li>
        <li>
            <a href="#">文章详细</a>
        </li>
    </ul>
</div>

<div class="row-fluid sortable ui-sortable">
    <div class="box span12">
        <div class="box-header well" data-original-title="">
            <h2><i class="icon-edit"></i>基本信息</h2>
            <div class="box-icon">
                <a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
                <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>

            </div>
        </div>
        <div class="box-content">
            <div class="form-horizontal">
                <div class="control-group">
                    <div class="controls">
                        <h3>基本信息</h3>
                    </div>
                </div>

                <div class="control-group">
                    <label class="control-label">别名</label>
                    <div class="controls">
                        <div class="input-prepend">
                            @if (string.IsNullOrEmpty(Model.ArticleKey.Alias))
                            {

                                @Html.TextBox("aliasinput", "", new { placeholder = "请输入文章别名" });

                            }
                            else
                            {
                                @Html.TextBox("aliasinput", Model.ArticleKey.Alias, new { placeholder = "不可修改", @readonly = "true" });

                            }
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">位置</label>
                    <div class="controls">
                        <div class="input-prepend">
                            @if (string.IsNullOrEmpty(Model.Index))
                            {
                                @Html.TextBox("indexinput", "", new { placeholder = "请输入文章位置" })
                             
                            }
                            else
                            {
                                @Html.TextBox("indexinput", Model.Index, new { placeholder = "请输入文章位置", @readonly = "true" })
                            }
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
@{
    var isVisible = string.IsNullOrEmpty(Model.ArticleKey.Alias) ? "" : "hide";
    <div class="row-fluid sortable ui-sortable @isVisible">
        <div class="box span12">
            <div class="box-header well" data-original-title="">
                <h2><i class="icon-edit"></i>Form Elements</h2>
                <div class="box-icon">

                    <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <input type="hidden" id="edit" value="@Html.Encode(!string.IsNullOrEmpty(Model.ArticleKey.Alias))" />
                @using (Html.BeginForm("GenTemplate", "magazine", FormMethod.Post, new { id = "templateForm", @class = "form-horizontal" }))
                {
                   
                    @Html.Hidden("year", Model.ArticleKey.Year)
                    @Html.Hidden("month", Model.ArticleKey.Month)
                   
                    <div class="control-group">
                        <div class="controls">
                            <h3>标题设置</h3>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <label class="checkbox inline">
                                <input type="checkbox" name="titleChoice" value="1">
                                标题 
                            </label>
                            <label class="checkbox inline">
                                <input type="checkbox" name="authorChoice" value="1">
                                作者 
                            </label>
                            <label class="checkbox inline">
                                <input type="checkbox" name="sourceChoice" value="1">
                                来源  
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <h3>内容设置</h3>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <label class="radio">
                                <input type="radio" name="contentChoice" value="1" checked="">
                                文字在上图片在下                              
                            </label>
                            <div style="clear: both"></div>
                            <label class="radio">
                                <input type="radio" name="contentChoice" value="2">
                                文字在下图片在上  
                            </label>
                            <div style="clear: both"></div>
                            <label class="radio">
                                <input type="radio" name="contentChoice" value="3">
                                文字在左图片在右  
                            </label>
                            <div style="clear: both"></div>
                            <label class="radio">
                                <input type="radio" name="contentChoice" value="4">
                                文字在右图片在左
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <h3>相关列表</h3>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            @*  <label class="radio">
                                <input type="radio" name="relatedChoice" value="1" checked="">
                                文字在上图片在下
                            </label>
                            <div style="clear: both"></div>*@
                            <label class="radio">
                                <input type="radio" name="relatedChoice" value="2">
                                文字在右图片在左 
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <h3>步骤列表</h3>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <label class="radio">
                                <input type="radio" name="phraseChoice" value="1">
                                文字在上图片在下
                            </label>
                            @*                            <div style="clear: both"></div>
                            <label class="radio">
                                <input type="radio" name="phraseChoice" value="2">
                                文字在右图片在左
                            </label>*@
                        </div>
                    </div>
                    <div class="form-actions">
                        <button id="templateBtn" type="button" class="btn btn-large btn-block btn-primary">生成模板</button>
                    </div>
                }

            </div>
        </div>
        <!--/span-->
    </div>
}

<div class="row-fluid sortable ui-sortable">
    <div class="box span12">
        <div class="box-header well" data-original-title="">
            <h2><i class="icon-edit"></i>Form Elements</h2>
            <div class="box-icon">
                <a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
                <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
                <a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
            </div>
        </div>
        <div class="box-content hide" id="controlUnitContainer">
            @using (Html.BeginForm("SaveTemplate", "magazine", FormMethod.Post, new { id = "genTemplateForm", @class = "form-horizontal", enctype = "multipart/form-data", onsubmit = "return iframeCallback(this)" }))
            {


                @Html.Hidden("year", Model.ArticleKey.Year)
                @Html.Hidden("month", Model.ArticleKey.Month)
                @Html.Hidden("alias", Model.ArticleKey.Alias)
                @Html.Hidden("index", Model.Index)
                <div class="control-group">
                    <div class="controls">
                        <h3>文章编辑</h3>
                    </div>
                </div>
                
               
                
                <div class="control-group" id="buttonContainer">
                    <div class="controls">
                        <button class="btn btn-primary">保存</button>
                        <button id="preview" type="button" class="btn">预览</button>
                    </div>
                </div>
@*                     <div class="form-actions">
                        <button id="save" type="button" class="btn btn-primary">保存</button>
                        <button id="preview" type="button" class="btn">预览</button>
                    </div>*@
            }
        </div>
    </div>
    <!--/span-->

</div>

@section JavaScript
{
    @Html.Partial("_BtnModalLoder")
    <script type="text/javascript">
        var type = "";
        $("button.modalLoder").live("click", function () {
            type = $(this).data("type");
            return false;
        });

        $(".modal a.btn-success").live("click", function () {
            $("#LinkType").val(type);
            return false;
        });


    </script>
    <script src="~/Scripts/backend/main.js"></script>
    <script type="text/javascript">
        $(function () {
            $("body").on("click", "#relatedBtnAdd", function () {
                var tr = $("#relatedTable tbody tr.hide").clone().removeClass("hide");
                var textareaName = "related_content";
                var textareaNameSelector = "textarea[name*=" + textareaName + "]";
                var fileInputName = "related_content_image";
                var fileInputNameSelector = "input[name*=" + fileInputName + "]";
                var hiddenInputName = "existed_related_content_image";
                var hiddenInputNameSelector = "input[name*=" + fileInputName + "]";
                var textAreaLength = $("#relatedTable tbody " + textareaNameSelector).length;
                var index = parseInt($("#relatedTable tbody " + textareaNameSelector)[textAreaLength - 1].name.match(/\d+/g)) + 1;
                tr.find(textareaNameSelector).attr("name", textareaName + "[" + index + "]");
                tr.find(fileInputNameSelector).attr("name", fileInputName + "[" + index + "]");
                tr.find(hiddenInputNameSelector).attr("name", fileInputName + "[" + index + "]");

                $("#relatedTable tbody").append(tr);



            });
            $("body").on("click", "#phraseBtnAdd", function () {
                var tr = $("#phraseTable tbody tr.hide").clone().removeClass("hide");
                var textareaName = "phrase_content";
                var textareaNameSelector = "textarea[name*=" + textareaName + "]";
                var fileInputName = "phrase_content_image";
                var fileInputNameSelector = "input[name*=" + fileInputName + "]";
                var hiddenInputName = "existed_phrase_content_image";
                var hiddenInputNameSelector = "input[name*=" + fileInputName + "]";
                var textAreaLength = $("#phraseTable tbody " + textareaNameSelector).length;
                var index = parseInt($("#phraseTable tbody " + textareaNameSelector)[textAreaLength - 1].name.match(/\d+/g)) + 1;
                tr.find(textareaNameSelector).attr("name", textareaName + "[" + index + "]");
                tr.find(fileInputNameSelector).attr("name", fileInputName + "[" + index + "]");
                tr.find(hiddenInputNameSelector).attr("name", fileInputName + "[" + index + "]");

                $("#phraseTable tbody").append(tr);

            });
            $("body").on("click", "#relatedBtnDel", function () {
                var $this = $(this);
                $this.parents("tr").remove();
                return false;

            });
            $("body").on("click", "#phraseBtnDel", function () {
                var $this = $(this);
                $this.parents("tr").remove();
                return false;

            });
            $('#templateBtn').click(function () {
                var index = $("#indexinput").val();
                var alias = $("#aliasinput").val();
                var edit = $("#edit").val();
                var url = $.no_cache_url($('#templateForm').attr("action")) + "&alias=" + alias + "&index=" + index + "&edit=" + edit;
                if (alias != null && alias != "" && index != null && index != "") {
                    $.ajax({
                        url: url,
                        type: "post",
                        data: $('#templateForm').serializeArray(),
                        success: function (o) {
                            $('#controlUnitContainer').find("#buttonContainer").before($(o));
                            $("#alias").val(alias);
                            $("#index").val(index);


                            $("#templateBtn").remove();
                            $("#controlUnitContainer").show();

                            //$('#controlUnitContainer').find("form").append($(o));
                            //2013-10-30 basilwang 处理uniform 否则上传控件不起作用
                            //$("input:checkbox, input:radio, input:file", $('#controlUnitContainer')).not('[data-no-uniform="true"],#uniform-is-ajax').uniform();
                        }

                    });
                }

            });
            $('#preview').click(function () {
                var alias = $("#aliasinput").val();
                var index = $("#indexinput").val();
                var url = $.no_cache_url($('#templateForm').attr("action")) + "&alias=" + alias + "&isEdit=false" + "&index=" + index;
                $.ajax({
                    url: url,
                    type: "post",
                    data: $('#templateForm').serializeArray(),
                    success: function (o) {
                        $('#alertModal .modal-body').html(o);
                        $('#alertModal').modal('show');
                        //$('#controlUnitContainer').find("#buttonContainer").before($(o));
                        //$('#controlUnitContainer').find("form").append($(o));
                        //2013-10-30 basilwang 处理uniform 否则上传控件不起作用
                        //$("input:checkbox, input:radio, input:file", $('#controlUnitContainer')).not('[data-no-uniform="true"],#uniform-is-ajax').uniform();
                    }

                });

            });
            (function () {
                var alias = $("#alias").val();
                var index = $("#index").val();
                if (alias != null && alias != "" && index != null && index != "") {
                    $('#templateBtn').click();

                }
            })();

        });
    </script>
}
